﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using UIWindows.Commands;

namespace UIWindows.ViewModels.Dialogs
{
    public class CustomDialogViewModel
    {
        public GlobalStatics.ParameterStatic Parameter { get; set; }
        public CustomDialogViewModel(GlobalStatics.ParameterStatic _parameter)
        {
            Parameter = _parameter;
        }
        public string Position { get; set; }
        
        public DelegateCommand<object> Determine => new DelegateCommand<object>(parameter => {
            if (int.TryParse(Position, out int result))
            {
                Parameter.WeighingConfig.CurrentLocation = result;
                Parameter.Save();
                CloseDialog(parameter);
            }
            else
            {
                MessageBox.Show("输入位置信息不合法！！！");
            }
          
        });
        public DelegateCommand<object> CloseDialogCommand => new DelegateCommand<object>(parameter => {
            CloseDialog(parameter);
        });

        /// <summary>
        /// 关闭窗口
        /// </summary>
        public void CloseDialog(object parameter)
        {
            //// 关闭弹窗的代码
            if (parameter is UserControl userControl)
            {
                MaterialDesignThemes.Wpf.DialogHost.CloseDialogCommand.Execute(null, userControl);
            }
        }
    }
}
